package org.store.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.store.domain.Identified;

import javax.sql.DataSource;
import java.util.List;


public abstract class AbstractDao<E extends Identified> {
    protected JdbcTemplate jdbcTemplate;

    @Autowired
    public void setDataSource(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    public abstract E getById(long id) throws DaoException;

    public abstract E save(E e) throws DaoException;

    public abstract boolean delete(E e) throws DaoException;

    public abstract E saveOrUpdate(E e) throws DaoException;

    public abstract List<E> saveAll(List<E> e) throws DaoException;

    public abstract boolean isExists(long id) throws DaoException;
}
